<?php
// +----------------------------------------------------------------------
// | Description: 视频数据表
// +----------------------------------------------------------------------
// | Author: xiaoliu <528772568@qq.com>
// +----------------------------------------------------------------------
namespace app\common\model;

use think\Model;

class Video extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    protected function getCoverAttr($value)
    {
        if (!$value) {
            $value = checkLinkAttr('/assets/img/def.png');
        }else{
            $value = checkLinkAttr($value);
        }
        return $value;
    }
    protected function getLinkAttr($value)
    {
        return checkLinkAttr($value);
    }
    
    public function Videogroup()
    {
        return $this->hasOne('VideoGroup', 'id', 'group_id')->field('id,name');
    }
    public function User()
    {
        return $this->hasOne('User', 'id', 'user_id')->field('id,nickname,avatar');
    }
    
    //点赞统计
    public function likenum() {
        return $this->hasMany('like', 'video_id', 'id')->field('id');
    }
    //点赞
    public function like() {
        return $this->hasOne('like', 'video_id', 'id')->field('id,video_id');
    }
}
